package Connection;

import java.util.ArrayList;
import java.util.Iterator;

public class ArrayList_1 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add("aaaa");
        arrayList.add(18);
        arrayList.add("hello");
        arrayList.add(true);
        //遍历
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.println("arrayList.get(i) = " + arrayList.get(i));
        }

        //forEach遍历
        for (Object ele : arrayList) {
            System.out.println("ele = " + ele);
        }
        //iterator 迭代器
        //1.从集合中获取一个迭代器
        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println("next = " + next);
        }

        //-----------------
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(19);
        arrayList1.add(18);
        arrayList1.add(20);
        arrayList1.add(17);

        //遍历
        for (int i = 0; i < arrayList1.size(); i++) {
            System.out.println("arrayList.get(i) = " + arrayList1.get(i));
        }

        //forEach遍历
        for (Integer ele : arrayList1) {
            System.out.println("ele = " + ele);
        }
        //iterator 迭代器
        //1.从集合中获取一个迭代器
        Iterator iterator1 = arrayList1.iterator();
        while (iterator1.hasNext()) {
            Object next = iterator1.next();
            System.out.println("next = " + next);
        }
    }
}